<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>图书归还</title>
        <meta name="description" content="图书归还">
        <meta name="keywords" content="图书归还">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../css/style.css">
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>图书归还</h1>
            </div>
            <div class="app-container">
                <div class="box">
                    <div class="filter-container">
                        <span>条件搜索： </span>
                        <el-input v-model="pagination.queryString" style="width: 200px;" class="filter-item" placeholder="请输入图书名称"></el-input>
                        <el-button @click="search()" class="dalfBut" type="primary" >搜索</el-button>
                    </div>
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column prop="book_id" align="center" label="图书编号"></el-table-column>
                        <el-table-column prop="book_name" label="图书名称" align="center"></el-table-column>
                        <el-table-column prop="author" label="作者" align="center"></el-table-column>
                        <el-table-column prop="library" label="图书馆" align="center"></el-table-column>
                        <el-table-column prop="position" label="位置" align="center"></el-table-column>
                        <el-table-column prop="state" label="状态" align="center"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">归还</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                        </el-pagination>
                    </div>
                    <div class="add-form">
                        <el-dialog title="归还图书" :visible.sync="dialogFormVisible4Edit">
                            <el-form :model="formData" status-icon ref="formData" label-position="right" label-width="100px">
                                <el-row>
                                    <el-col :span="24">
                                        <el-form-item label="图书id" prop="book_id">
                                            <el-input type="book_id" v-model="formData.book_id" readonly/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="24">
                                        <el-form-item label="借阅证号" prop="loan_card_id">
                                            <el-input type="loan_card_id" v-model="formData.loan_card_id" readonly/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-form>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="resetForm()">取消</el-button>
                                <el-button type="primary" @click="submitForm()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>
                </div>
                </div>
            </div>
        </div>
    </body>
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script>
        var vue = new Vue({
            el: '#app',

            data:{
                value: '',
                pagination: {//分页相关模型数据
					  currentPage: 1,//当前页码
					  pageSize:5,//每页显示的记录数
					  total:0,//总记录数
					  queryString:null//查询条件
				},
                formData:{
                    loan_card_id:'',
                    book_id:''
                },
                readonly: true,
				dataList: [],//当前页要展示的分页列表数据
                dialogFormVisible4Edit:false
            },
            //钩子函数，VUE对象初始化完成后自动执行
            created() {
                this.findPage();
            },
            methods: {
                //分页查询
                findPage() {
                    var param = {
                        currentPage: this.pagination.currentPage,
                        pageSize:this.pagination.pageSize,
                        queryString:this.pagination.queryString
                    }
                    axios.post("/bookreturn/findPage.do",param).then((res) => {
                        this.pagination.total = res.data.total;
                        this.dataList = res.data.rows;
                    });
                },
                search() {
                    this.pagination.currentPage = 1;
                    this.findPage();
                },
                //切换页码
                handleCurrentChange(currentPage) {
                    this.pagination.currentPage = currentPage;
                    this.findPage();
                },
                handleUpdate(row){
                    this.formData.book_id = row.book_id;
                    axios.post("/bookreturn/findById.do",this.formData).then((res) => {
                        this.formData.loan_card_id = res.data.data;
                    });
                    this.dialogFormVisible4Edit = true;
                },
                submitForm() {
                    axios.post("/bookreturn/returnbook.do",this.formData).then((res)=>{
                        if(res.data.flag){
                            this.$message({
                                message:res.data.message,
                                type:'success'
                            });
                        }else{
                            this.$message.error(res.data.message);
                        }
                    }).finally(() =>{
                        this.findPage();
                        this.dialogFormVisible4Edit = false;
                    });
                },
                resetForm() {
                    this.dialogFormVisible4Edit=false;
                    this.formData.loan_card_id='';
                }

            }
        })
    </script>
</html>